<?php
/**
* @package YaForms
* @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
* @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
* YaForms! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
* Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
*/

defined( '_VALID_MOS' ) or die( 'Restricted access' );

function showEditFields( $option, $formid, &$items, &$itlists, $afcfg_usebehelper='0', $afcfg_fieldsdefaultlayout=''  ) {

   global $database, $mainframe;
   
   $a_typeslist = mosHTML::selectList( $itlists['a_types'], 'type[]', 'class="text_area" size="1"', 'value', 'text' );
   $a_requlist  = mosHTML::selectList( $itlists['a_requ'], 'required[]', 'class="text_area" size="1"', 'value', 'text' );
   $a_validlist = mosHTML::selectList( $itlists['a_valid'], 'validation[]', 'class="text_area" size="1"', 'value', 'text'  );
   $a_ronlylist = mosHTML::selectList( $itlists['a_ronly'], 'readonly[]', 'class="text_area" size="1"', 'value', 'text'  );
   $addFieldx   = mosHTML::selectList( $itlists['addFieldx'], 'addFieldx', 'class="text_area" onChange="extrainputbox(this.form)"', 'value', 'text', 'n' );
   $dolayout = urldecode( $afcfg_fieldsdefaultlayout );

    //Загружаем библиотеки и плагины jquery
	//mosCommonHTML::loadJquery();
	$mainframe->addJS( JPATH_SITE.'/components/com_yaforms/includes/js/cnet/jquery.msAccordion.js');
	$mainframe->addCSS( JPATH_SITE.'/components/com_yaforms/includes/js/cnet/acordeon.css');

   ?>

<table border="0" cellpadding="3" cellspacing="0" width="100%" class="adminform">
  <tr>
    <th> </th>
  </tr>
  <tr>
    <td><div id="accordion3" class="accordionWrapper">
        <?php
      $i=0;

      if ($formid == ''){

                       $i=1;
                       echo "<div class=\"set\"><input type=\"hidden\" name=\"form_id[]\" value=\"".$formid."\" />
                                   <input type=\"hidden\" name=\"item_id[]\" value=\"\" /><div class=\"title\"><div class=\"titleleft\">".YAF_FORM_FIELD." #".$i."</div><div class=\"titleright\">".YAF_FORM_ORDER.": <input class=\"text_area\" type=\"text\" name=\"item_ordering[]\" maxlength=\"4\" align=\"center\" style=\"width:25px;text-align:center;\" value=\"\"/></div></div>
			   						
									<div class=\"content\">
									
									<div class=\"fildwith\">
											
  									<!-- порядок -->
                                   <div class=\"affields_2\" width=\"90px\">
								   ".YAF_FORM_ORDER."<br />
								   <input class=\"text_area\" type=\"text\" name=\"item_ordering[]\" maxlength=\"4\" align=\"center\" style=\"width:25px;text-align:center;\" value=\"\"/> ".mosToolTip(YAF_HELPER_FIELD_ORDER)."
								   </div>
                            		
									<!-- имя поля -->
                                   <div class=\"affields_2\" width=\"128px\">
								   ".YAF_FORM_FIELDNAME."<br />				
                                   <input class=\"text_area\" type=\"text\" size=\"20\" name=\"name[]\" value=\"\" /> 
								   ".mosToolTip(YAF_HELPER_FIELD_FIELDNAME)."
								   </div>";
								   
								   //Тип поля
								   
                                   echo "<div class=\"affields_2\" width=\"90px\">
								   ".YAF_FORM_FIELDTYPE."<br />
								   ".$a_typeslist." ".mosToolTip(YAF_HELPER_FIELD_FIELDTYPE)."
								   </div>";
								   
								   //Обязательно или нет
								   
                                   echo "<div class=\"affields_2\" width=\"90px\">
								   ".YAF_FORM_REQUIRED."<br />
								   ".$a_requlist." ".mosToolTip(YAF_HELPER_FIELD_REQUIRED)."
								   </div>";
								   
								   //Выбор валидации
								   
                                   echo "<div class=\"affields_2\" width=\"90px\">
								   ".YAF_FORM_VALIDE."<br />
								   ".$a_validlist." ".mosToolTip(YAF_HELPER_FIELD_VALIDE)."
								   </div>";
								   
								   //Только чтение
                                 
								   echo "<div class=\"affields_2\" width=\"90px\">
								   ".YAF_FORM_READONLY."<br />
								   ".$a_ronlylist." ".mosToolTip(YAF_HELPER_FIELD_READONLY)."</div>
                                	
									<!-- Собственный код -->
									<div class=\"affields_2\" width=\"128px\">
									".YAF_FORM_CUSTOMCODE."<br />
                                   <input class=\"text_area\" type=\"text\" name=\"customcode[]\" value=\"\"/> 
								   ".mosToolTip(YAF_HELPER_FIELD_CUSTOMCODE)."</div>
                                	
									</div><div class=\"fildwith_2\">
									
									<!-- Значение -->
									<div class=\"affields_2\" width=\"128px\">
									".YAF_FORM_VALUES."<br />
									<textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"5\" name=\"values[]\" /></textarea> ".mosToolTip(YAF_HELPER_FIELD_VALUES)."
									</div>
                               		
									<!-- Значение по умолчанию -->
									<div class=\"affields_2\" width=\"128px\">
									".YAF_FORM_DEFVALUES."<br />
                                   <textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"5\" name=\"default_values[]\" /></textarea> ".mosToolTip(YAF_HELPER_FIELD_DEFVALUES)."
								   </div>
                                	
									<div class=\"affields_2\" width=\"128px\">
									".YAF_FORM_LAYOUT."<br />
                                   <textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"5\" name=\"layout[]\" />".$dolayout."</textarea> ".mosToolTip(YAF_HELPER_FIELD_LAYOUT)."
								   </div>
								&nbsp;</div></div>";

			 } else {

			   foreach ($items as $item) {
                           $i++;
                           $item->values = str_replace("<","&lt;",$item->values);
	                   $item->values = str_replace(">","&gt;",$item->values);
                           $item->default_values = str_replace("<","&lt;",$item->default_values);
	                   $item->default_values = str_replace(">","&gt;",$item->default_values);
	                   $item->layout = str_replace("<","&lt;",$item->layout);
                           $item->layout = str_replace(">","&gt;",$item->layout);
					 if ($i > 1){
                                   $del_img =  "
								   
	&nbsp;<a class=\"button\" onclick=\"document.location='index2.php?option=com_yaforms&task=delrow&id=".$formid."&itemdel=".$item->item_id."'\" title='".YAF_FORM_ITEMDEL."';>".YAF_FORM_ITEMDEL."</a>
								   
								   ";
                                }else{
								$del_img = '';
								}
	 
                           echo "<div class=\"set\"><input type=\"hidden\" name=\"form_id[]\" value=\"".$formid."\" />
                                   <input type=\"hidden\" name=\"item_id[]\" value=\"".$item->item_id."\" /><div class=\"title\"><div class=\"titleleft\">".YAF_FORM_FIELD." #".$i." - ".$item->name."</div><div class=\"titleright\">".YAF_FORM_ORDER.": <input class=\"text_area\" type=\"text\" name=\"item_ordering[]\" maxlength=\"4\" align=\"center\" style=\"width:25px;text-align:center;\" value=\"".$item->item_ordering."\"/> ".$del_img." </div></div>
			   						<div class=\"content\">
							
									<div class=\"fildwith\">
	
									<!-- имя поля -->
                                   <div class=\"affields_2\" width=\"128px\">".YAF_FORM_FIELDNAME."<br />			
                                   <input class=\"text_area\" type=\"text\" size=\"20\" name=\"name[]\" value=\"".$item->name."\" /> ".mosToolTip(YAF_HELPER_FIELD_FIELDNAME)."
								   </div>";
								   
								   //Тип поля
                                   $a_typeslistf = mosHTML::selectList( $itlists['a_types'], 'type[]', 'class="text_area" size="1"', 'value', 'text', $item->type );
								   
                                   echo "<div class=\"affields_2\" width=\"90px\">".YAF_FORM_FIELDTYPE."<br />
								   ".$a_typeslistf." ".mosToolTip(YAF_HELPER_FIELD_FIELDTYPE)."
								   </div>";
								   
								   //Обязательно или нет
                                   $a_requlistf = mosHTML::selectList( $itlists['a_requ'], 'required[]', 'class="text_area" size="1"', 'value', 'text', $item->required );
								   
                                   echo "<div class=\"affields_2\" width=\"90px\">".YAF_FORM_REQUIRED."<br />
								   ".$a_requlistf." ".mosToolTip(YAF_HELPER_FIELD_REQUIRED)."
								   </div>";
								   
								   //Выбор валидации
                                   $a_validlistf = mosHTML::selectList( $itlists['a_valid'], 'validation[]', 'class="text_area" size="1"', 'value', 'text', $item->validation );
								   
                                   echo "<div class=\"affields_2\" width=\"90px\">".YAF_FORM_VALIDE."<br />
								   ".$a_validlistf." ".mosToolTip(YAF_HELPER_FIELD_VALIDE)."
								   </div>";
								   
								   //Только чтение
                                   $a_ronlylistf = mosHTML::selectList( $itlists['a_ronly'], 'readonly[]', 'class="text_area" size="1"', 'value', 'text', $item->readonly );
                                   
								   echo "<div class=\"affields_2\" width=\"90px\">".YAF_FORM_READONLY."<br />
								   ".$a_ronlylistf." ".mosToolTip(YAF_HELPER_FIELD_READONLY)."</div>
                                	
									<!-- Собственный код -->
									<div class=\"affields_2\" width=\"128px\">".YAF_FORM_CUSTOMCODE."<br />
                                   <input class=\"text_area\" type=\"text\" name=\"customcode[]\" value=\"".$item->customcode."\"/> ".mosToolTip(YAF_HELPER_FIELD_CUSTOMCODE)."
								   </div>
                                	</div>
									<div class=\"fildwith_2\">
									
									<!-- Значение -->
									<div class=\"affields_2\" width=\"128px\">".YAF_FORM_VALUES."<br />
									<textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"5\" name=\"values[]\" />".$item->values."</textarea> ".mosToolTip(YAF_HELPER_FIELD_VALUES)."
									</div>
                               		
									<!-- Значение по умолчанию -->
									<div class=\"affields_2\" width=\"128px\">".YAF_FORM_DEFVALUES."<br />
                                   <textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"5\" name=\"default_values[]\" />".$item->default_values."</textarea> ".mosToolTip(YAF_HELPER_FIELD_DEFVALUES)."
								   </div>
                                	
									<div class=\"affields_2\" width=\"128px\">".YAF_FORM_LAYOUT."<br />
                                   <textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"5\" name=\"layout[]\" />".($item->layout ? $item->layout : $dolayout)."</textarea> ".mosToolTip(YAF_HELPER_FIELD_LAYOUT)."
								   </div>
								</div>
								</div></div>";
                           }
                         }

      $a_typeslist  = eregi_replace( 'ze="1">', 'ze="1">\\', $a_typeslist );
      $a_requlist   = eregi_replace( 'ze="1">', 'ze="1">\\', $a_requlist );
      $a_validlist  = eregi_replace( 'ze="1">', 'ze="1">\\', $a_validlist );
      $a_ronlylist  = eregi_replace( 'ze="1">', 'ze="1">\\', $a_ronlylist );
      $a_typeslist  = eregi_replace( 'n>', 'n>\\', $a_typeslist );
      $a_requlist   = eregi_replace( 'n>', 'n>\\', $a_requlist );
      $a_validlist  = eregi_replace( 'n>', 'n>\\', $a_validlist );
      $a_ronlylist  = eregi_replace( 'n>', 'n>\\', $a_ronlylist );
      $a_typeslist  = eregi_replace( 'ct>', 'ct>\\', $a_typeslist );
      $a_requlist   = eregi_replace( 'ct>', 'ct>\\', $a_requlist );
      $a_validlist  = eregi_replace( 'ct>', 'ct>\\', $a_validlist );
      $a_ronlylist  = eregi_replace( 'ct>', 'ct>\\', $a_ronlylist );

      $dolayout     = base64_encode( $dolayout );
      
      echo '<script type="text/javascript" src="'.JPATH_SITE.'/components/com_yaforms/includes/js/base64/webtoolkit.base64.js"></script>';
                                echo "<script type=\"text/javascript\">

                                     function extrainputbox(form) {

                                     var b64layout = '".$dolayout."';
                                     var getlayout = Base64.decode(b64layout);
                                     var einputs1 = '<div class=\"set_add\"><input type=\"hidden\" name=\"form_id[]\" value=\"".$formid."\" /><input type=\"hidden\" name=\"item_id[]\" value=\"\" /><div class=\"title_add\"><b>".YAF_FORM_FIELD."&nbsp;#'; var einputs2 = ':</b> &nbsp;<font color=\"#FF0000\" size=\"2\">".YAF_WARNADDFILD."</font></div><div class=\"content_add\">\
					 <div class=\"fildwith\"><div class=\"affields_2\" width=\"90px\">".YAF_FORM_ORDER."<br /><input class=\"text_area\" type=\"text\" name=\"item_ordering[]\" maxlength=\"4\" style=\"width:25px;text-align:center;\" value=\"\"/></div>\
                                     <div class=\"affields_2\" width=\"128px\">".YAF_FORM_FIELDNAME."<br /><input class=\"text_area\" type=\"text\" size=\"20\" name=\"name[]\" value=\"\" /></div>\
                                     <div class=\"affields_2\" width=\"90px\">".YAF_FORM_FIELDTYPE."<br />\\".$a_typeslist."</div>\
                                     <div class=\"affields_2\" width=\"90px\">".YAF_FORM_REQUIRED."<br />\\".$a_requlist."</div>\
                                     <div class=\"affields_2\" width=\"90px\">".YAF_FORM_VALIDE."<br />\\".$a_validlist."</div>\
									 <div class=\"affields_2\" width=\"90px\">".YAF_FORM_READONLY."<br />\\".$a_ronlylist."</div>\
									 <div class=\"affields_2\" width=\"128px\">".YAF_FORM_CUSTOMCODE."<br /><input class=\"text_area\" type=\"text\" name=\"customcode[]\" value=\"\"/></div>\
                                     </div><div class=\"fildwith_2\"><div class=\"affields_2\" width=\"128px\">".YAF_FORM_VALUES."<br /><textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"4\" name=\"values[]\" /></textarea></div>\
                                     <div class=\"affields_2\" width=\"128px\">".YAF_FORM_DEFVALUES."<br /><textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"4\" name=\"default_values[]\" /></textarea></div>\
                                     <div class=\"affields_2\" width=\"128px\">".YAF_FORM_LAYOUT."<br /><textarea class=\"text_area\" type=\"text\" cols=\"25\" rows=\"4\" name=\"layout[]\" />'+getlayout+'</textarea></div>\
                                     </div></div></div>';

                                     var numObj = parseInt(form.addFieldx.value);
                                     var html = '';
                                     var container = document.getElementById('divAddField');

                                     if (numObj > 0) {
                                         for(i=1; i<=numObj; i++) {
                                             var n2 = ".$i." - 1 + i;
                                             n2++;
                                             einputs = (einputs1 + n2 + einputs2);
                                             html += (einputs);
                                         }
                                     }

                                     container.innerHTML = html;

                                }

                                </script>
                                     ";
                ?>
        <div id="divAddField" width="100%"></div>
        <br />
        <input type="hidden" name="id" value="<?php echo $formid; ?>" />
        <input type="hidden" name="option" value="<?php echo $option; ?>" />
        <input type="hidden" name="boxchecked" value="0" />
        <input type="hidden" name="task" value="" />
      </div></td>
  </tr>
</table>
</form>
<div class="affields_2">
  <form name="adminForm2" method="" action="">
    <div width="100%" align="right" height="30"> <?php echo YAF_FORM_NEWFIELD.' '.$addFieldx.mosToolTip(YAF_HELPER_FIELD_NEWFIELD);?> </div>
  </form>
</div>
<?php

}

?>
<script language="javascript" type="text/javascript">
$(document).ready(function() {

						   $("#accordion3").msAccordion({defaultid:0, vertical:true});
						   $("#accordion4").msAccordion({defaultid:0, vertical:true, event:'mouseover'});
						   }
						   )
</script>
